package ge.home.app.globals;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * Created by bacho on 3/17/14.
 */
public class Grid extends LinearLayout {
    private Context context;

    public Grid(Context ctx) {
        super(ctx);
        context = getContext();
        this.setScrollbarFadingEnabled(false);
        this.addView(createGrid());
    }

    public HorizontalScrollView createGrid() {
        HorizontalScrollView hsv = new HorizontalScrollView(context);
        hsv.setFillViewport(true);
        ScrollView sv = new ScrollView(context);
        sv.setFillViewport(true);
        LinearLayout lin = new LinearLayout(context);
        /*sv.setScrollbarFadingEnabled(false);*/

        TableLayout ll = new TableLayout(context);
        ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ll.setLayoutParams(p);
        sv.addView(ll);
        lin.addView(sv); //TODO tashti moita
        hsv.addView(lin);

        for (int i = 1; i < 100; i++) {
            TableRow tbrow = new TableRow(context);
            tbrow.setBackgroundColor(Color.BLACK);
            tbrow.setPadding(1, 0, 0, 1);
            for (int j = 1; j <= 10; j++) {
                LinearLayout l = new LinearLayout(context);
                l.setBackgroundColor(Color.BLACK);
                l.setPadding(0, 1, 1, 0);
                TextView tv1 = new TextView(context);
                tv1.setBackgroundColor(Color.WHITE);
                tv1.setWidth(150);
                tv1.setHeight(30);
                tv1.setGravity(Gravity.CENTER_HORIZONTAL);
                String s1 = Integer.toString(i);
                String s2 = Integer.toString(j);
                String s3 = s1 + s2;
                int id = Integer.parseInt(s3);
                tv1.setId(id);

                tv1.setText(i + "-" + j);
                l.addView(tv1);

                tbrow.addView(l);
            }
            ll.addView(tbrow);
        }
        return hsv;
    }
}
